package JFrame;

import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;

class myJFrame extends JFrame {
        myJFrame(String name,int x,int y,int m,int n){
        setTitle(name);
        setBounds(x,y,m,n);
        setVisible(true);
        setLayout(new FlowLayout(FlowLayout.LEFT));
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        creat();
    }

    private void creat() {
        JTextField text1=new JTextField(15);
        JTextField text2 = new JTextField(15);
        JLabel label1=new JLabel("输入：");
        JLabel label2=new JLabel("结果：");
        add(label1);
        add(text1);
        add(label2);
        add(text2);
        JButton btn=new JButton("去除非数字");
        add(btn);
        btn.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String getString=text1.getText();
                String aferReplace=getString.replaceAll("[^0-9]","");
                text2.setText(aferReplace);
            }
        });
    }
}
class ExericeJFrame{
    public static void main(String[] args) {
        myJFrame jFrame=new myJFrame("去除非数字字符",200,200,500,300);
    }
}